package com.reremouse.rerebbs.web.mb.mag;

import com.reremouse.rerebbs.dao.IBbsUserDAO;
import com.reremouse.rerebbs.dao.IBbsZoneDAO;
import com.reremouse.rerebbs.model.BbsUser;
import com.reremouse.rerebbs.model.BbsZone;
import com.reremouse.util.SpringHelper;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@ManagedBean
@ViewScoped
public class AAZone
        implements Serializable {
    IBbsZoneDAO bbsZoneDAO = (IBbsZoneDAO) SpringHelper.getSpringBean("BbsZoneDAO");
    IBbsUserDAO bbsUserDAO = (IBbsUserDAO) SpringHelper.getSpringBean("BbsUserDAO");
    BbsZone zone;
    boolean flag = false;
    String str = "";
    List<BbsUser> newUsers = new ArrayList();

    public String getStr() {
        return this.str;
    }

    public void setStr(String str) {
        this.str = str;
    }

    public List<BbsUser> getNewUsers() {
        return this.newUsers;
    }

    public void setNewUsers(List<BbsUser> newUsers) {
        this.newUsers = newUsers;
    }

    public boolean isFlag() {
        return this.flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    public BbsZone getZone() {
        return this.zone;
    }

    public void setZone(BbsZone zone) {
        this.zone = zone;
    }

    @PostConstruct
    public void init() {
        HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        String id = req.getParameter("id");
        if (id != null) {
            this.zone = this.bbsZoneDAO.findById(Long.valueOf(Long.parseLong(id)));
            this.flag = true;
        } else {
            this.zone = new BbsZone();
        }
        if (this.zone.getManagers() == null) {
            this.zone.setManagers(new ArrayList());
        }
    }

    public void deleteMag(long id) {
        BbsUser u = null;
        List<BbsUser> us = this.zone.getManagers();
        for (BbsUser b : us) {
            if (id == b.getId().longValue()) {
                u = b;
                break;
            }
        }
        if (u != null) {
            us.remove(u);
        }
    }

    public void addMag(long id) {
        BbsUser u = null;
        List<BbsUser> us1 = this.zone.getManagers();
        for (BbsUser b : this.newUsers) {
            if (id == b.getId().longValue()) {
                u = b;
                break;
            }
        }
        if (u != null) {
            this.newUsers.remove(u);
            us1.add(u);
        }
    }

    public void searchUser() {
        this.newUsers = this.bbsUserDAO.findBbsUsersLikeUrn(this.str);
    }

    public String done() {
        FacesContext fc = FacesContext.getCurrentInstance();
        if (!this.flag) {
            this.bbsZoneDAO.save(this.zone);
        } else {
            this.bbsZoneDAO.update(this.zone);
        }
        return "ListZone?faces-redirect=true";
    }
}



/* Location:           F:\jsp源码\蝙蝠论坛系统\rerebbs\WEB-INF\classes\

 * Qualified Name:     com.reremouse.rerebbs.web.mb.mag.AAZone

 * JD-Core Version:    0.7.0.1

 */